import 'package:flutter/material.dart';

class EmptyWidget extends StatelessWidget {
  final String message;
  final String imagePath;
  final double imageSize;
  final String buttonText;
  final VoidCallback? onButtonPressed;

  const EmptyWidget({
    Key? key,
    this.message = "暂无数据",
    this.imagePath = "assets/images/empty_task.png",
    this.imageSize = 200.0,
    this.buttonText = "刷新试试",
    this.onButtonPressed,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // 图片区域
            if (imagePath.startsWith('http'))
              Image.network(
                imagePath,
                width: imageSize,
                height: imageSize,
                fit: BoxFit.contain,
                errorBuilder: (context, error, stackTrace) => _buildDefaultIcon(),
              )
            else
              Image.asset(
                imagePath,
                width: imageSize,
                height: imageSize,
                fit: BoxFit.contain,
                errorBuilder: (context, error, stackTrace) => _buildDefaultIcon(),
              ),

            const SizedBox(height: 16),

            // 提示文字
            Text(
              message,
              style: const TextStyle(
                fontSize: 16,
                color: Colors.grey,
                fontWeight: FontWeight.w500,
              ),
              textAlign: TextAlign.center,
            ),

            const SizedBox(height: 24),

            // 刷新按钮（可选）
            if (onButtonPressed != null)
              ElevatedButton(
                onPressed: onButtonPressed,
                style: ElevatedButton.styleFrom(
                  backgroundColor: Theme.of(context).primaryColor,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(20),
                  ),
                  padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 10),
                ),
                child: Text(
                  buttonText,
                  style: const TextStyle(
                    fontSize: 14,
                    color: Colors.white,
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }

  Widget _buildDefaultIcon() {
    return Icon(
      Icons.inbox_outlined,
      size: imageSize,
      color: Colors.grey[300],
    );
  }
}